import 'package:bruno/bruno.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:niuniu/common/constant/AppColor.dart';
import 'package:niuniu/common/router/RouteNames.dart';
import 'package:niuniu/pages/login/controller.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);

  // 主视图
  Widget buildView() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      // crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        GestureDetector(
          child: Container(
            margin: EdgeInsets.only(top: 10.h, bottom: 10.h),
            padding: EdgeInsets.all(10.w),
            width: 150.w,
            height: 150.w,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(200.w),
              color: AppColor.themeColor,
            ),
            child: Center(
              child: Text(
                "登 录",
                style: TextStyle(fontSize: 30, color: AppColor.firstFontColor),
              ),
            ),
          ),
          onTap: () {
            print("登录");
          },
        ),
        SizedBox(height: 30.h),
        BrnRadioButton(
          radioIndex: 10,
          isSelected: controller.isAgree,
          childOnRight: true,
          child: RichText(
              text: TextSpan(children: [
            TextSpan(
              text: '已阅读并同意',
              style: TextStyle(color: AppColor.secondFontColor),
            ),
            TextSpan(
              text: ' 用户协议 ',
              style: TextStyle(color: AppColor.firstFontColor),
              recognizer: TapGestureRecognizer()
                ..onTap = () async {
                  Get.toNamed(RouteNames.userAgreement);
                },
            ),
            TextSpan(
              text: '和',
              style: TextStyle(color: AppColor.secondFontColor),
            ),
            TextSpan(
              text: ' 隐私政策',
              style: TextStyle(color: AppColor.firstFontColor),
              recognizer: TapGestureRecognizer()
                ..onTap = () async {
                  Get.toNamed(RouteNames.privacyPolicy);
                },
            )
          ])),
          // child: const Text("已阅读并同意 用户协议 和 隐私政策"),
          onValueChangedAtIndex: (index, value) {
            print(index);
            print(value);
            controller.isAgree = false;
          },
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      init: LoginController(),
      id: "login-page",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text(""),
            leading: GestureDetector(
                child: Padding(
                    padding: EdgeInsets.only(left: 15.w, top: 15.h),
                    child: FaIcon(FontAwesomeIcons.xmark,
                        color: AppColor.iconColor)),
                onTap: () {
                  Get.back();
                }),
          ),
          body: Container(
            margin: EdgeInsets.only(bottom: 200.h),
            alignment: Alignment.topCenter,
            child: buildView(),
          ),
        );
      },
    );
  }
}
